home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir42 / c7105.zip / VALIDATE.TPX < prev    next >
Text File  |  1994-03-02  |  18KB  |  466 lines

  1. #!┌───────────────────────────┤Template Segment├───────────┬─────────────────┐
  2. #!│                              Validate.TPX              │Version: 3007.105│
  3. #!├───────────────────────────────┤Contents├───────────────┴─────────────────┤
  4. #!│Structure             Type       Description                              │
  5. #!│────────────────────  ─────────  ─────────────────────────────────────────│
  6. #!│Validate              PROCEDURE  Lookup invalid field value from a file   │
  7. #!├───────────────────────────────┤Comments├─────────────────────────────────┤
  8. #!│Version   Comments                                                        │
  9. #!│────────  ────────────────────────────────────────────────────────────────│
  10. #!│3007.000  Release of CDD3 version 3007 templates                          │
  11. #!│3007.103  Repaired Validate PROCEDURE                                     │
  12. #!│3007.105  Repaired Validate PROCEDURE                                     │
  13. #!└──────────────────────────────────────────────────────────────────────────┘
  14. #!
  15. #PROCEDURE(Validate,'Lookup invalid field value from a file'),SCREEN,PULLDOWN
  16. #!
  17. #!┌──────────────────────────┤Procedure Template├──────────┬─────────────────┐
  18. #!│                                Validate                │Version: 3007.103│
  19. #!├──────────────────────────────┤Description├─────────────┴─────────────────┤
  20. #!│Used as a Post-Edit (When Field Is Completed) procedure, to confirm that  │
  21. #!│an entered value is contained in a file.  This functionality is replaced  │
  22. #!│in 3007 with the Browse Procedure, but is provided for compatability      │
  23. #!│with applications developed prior to 3007.                                │
  24. #!│                                                                          │
  25. #!│A Validate procedure MUST be called as a "When Field Is Completed"        │
  26. #!│procedure                                                                 │
  27. #!├───────────────────────────────┤Comments├─────────────────────────────────┤
  28. #!│Version   Comments                                                        │
  29. #!│────────  ────────────────────────────────────────────────────────────────│
  30. #!│3007.000  Release of CDD3 version 3007 templates                          │
  31. #!│3007.103  Changed UpdateProcedure ROUTINE (Added SELECT(?List))           │
  32. #!│3007.103  Added support for SAV::PullDownOpened for Lookup.               │
  33. #!│          This support was added because any screen or pulldown needs to  │
  34. #!│          be closed so CHANGE only affect the calling screen.             │
  35. #!│          Added INSERT of SaveRangeFields to initialize SAV:: values if   │
  36. #!│          a Range Limit is used.                                          │
  37. #!│          Added call to %EditCodeLocator GROUP in CASE FIELD() code       │
  38. #!│3007.105  Completed support for PullDowns                                 │
  39. #!│          Modified ResetFirst code to handle initial load of current value│
  40. #!└──────────────────────────────────────────────────────────────────────────┘
  41. #!
  42. #MAP('BROWSE.INC')
  43. #PROJECT('%clapfx%BROWS.LIB')
  44. #PROTOTYPE('')
  45. #!
  46. #PROMPT('Range &Limit Field',COMPONENT),%KeyRangeField
  47. #PROMPT('Range &Value Field',FIELD),%RangeValue
  48. #PROMPT('Record Filter',@S180),%RecordFilter
  49. #PROMPT('Lookup Field',COMPONENT),%LookupField
  50. #PROMPT('Input Field Picture',@S30),%LookupPicture
  51. #PROMPT('Locator Field',COMPONENT),%Locator
  52. #PROMPT('Incremental Locator',CHECK),%IncrementalLocator
  53. #PROMPT('Display Key',KEY),%DisplayKey
  54. #PROMPT('Upd&ate Procedure',PROCEDURE),%UpdateProc
  55. #PROMPT('Enable Hot Records',CHECK),%HotBar
  56. #PROMPT('Lookup Hot Key',KEYCODE),%LookupHotKey
  57. #PROMPT('Disable Memo Access',CHECK),%NoMemo
  58. #!
  59. #INSERT(%SetBrowseSymbols)
  60. #IF(%LookupField = %Null)
  61.   #SET(%ErrorMessage, (%Procedure & ' ERROR: Lookup Field is required.'))
  62.   #ERROR(%ErrorMessage)
  63. #ENDIF
  64. #!
  65. #FIX(%File,%Primary)
  66. #SET(%LookupKey,%PrimaryKey)
  67. #FIX(%Field,%LookupField)
  68. #!
  69. #IF(%FieldType='STRING' OR %FieldType='CSTRING' OR %FieldType='PSTRING')
  70.   #SET(%LookupType,'STRING')
  71. #ENDIF
  72. #IF(%DisplayKey = %Null)
  73.   #SET(%DisplayKey,%PrimaryKey)
  74. #ENDIF
  75. #INSERT(%BrowseErrorCheck)
  76. #INSERT(%StandardHeader)
  77.  
  78. %Procedure       PROCEDURE
  79.  
  80. #FIX(%ScreenField,'?List')
  81. Queue            QUEUE
  82.                    STRING(%ScreenFieldQueueSize)
  83.                  END
  84. #INSERT(%SetupKeyRangeFields)
  85.  
  86. #IF(%UpdateProc)
  87. UpdateMode       BYTE(0)
  88. UpdateSuccessful BYTE(0)
  89. #ENDIF
  90. #IF(%LookupPicture)
  91. DeformatString   STRING(80)
  92. #ENDIF
  93. ButtonIsDisabled BYTE                            !Flag to allow button enable
  94.  
  95. #INSERT(%FileControl)
  96. #IF(%KeyRangeField)
  97.   #IF(%TotalExists)
  98. InitTotals       BYTE(1)
  99.   #ENDIF
  100. #ENDIF
  101. CalledAsLookup   BYTE(1)
  102. ListInitialized  BYTE(0)
  103. InitialLoad      BYTE(1)
  104. %LocalData
  105. %ScreenStructure
  106. #IF(%PullDownStructure)
  107. SAV::PullDownOpened BYTE(0)
  108. %PulldownStructure
  109. #ENDIF
  110.  
  111. #EMBED('Data Section')
  112.  
  113.   CODE
  114.   ListInitialized = FALSE
  115.   #EMBED('Setup Procedure')
  116.   #INSERT(%FileControl)
  117.   #EMBED('Before Validate Lookup')
  118.   #IF(%LookupHotKey)
  119.   IF KEYCODE() <> %LookupHotKey                #<!If not requested by hot key
  120.     #INSERT(%LookupRecord)
  121.   END                                            !End IF
  122.   #ELSE
  123.   #INSERT(%LookupRecord)
  124.   #ENDIF
  125.   OPEN(Screen)                                   !Open the screen
  126.   #EMBED('Setup Screen')
  127.   DISPLAY                                        !Display screen fields
  128.   #INSERT(%SaveRangeFields)
  129.   #IF(%Pulldown)                                #!If a Pulldown exists
  130.   OPEN(%Pulldown)                              #<!Open the Pulldown
  131.   SAV::PullDownOpened = True
  132.   #EMBED('Setup Pulldown')
  133.   #ENDIF
  134.   #IF(%TotalExists)
  135.     #IF(NOT %PreListEntry)
  136.   DO InitializeTotals
  137.     #ENDIF
  138.   #ENDIF
  139.   #INSERT(%AddFixedListLines)
  140.   #INSERT(%BeginBrowse)
  141.   ListInitialized = TRUE
  142.   LOOP                                           !Process browse requests
  143.     #EMBED('Top of BrowseAction LOOP')
  144.     CASE BrowseAction(%Primary,%DisplayKey,Queue)#<!Browse the file
  145.     OF FormatQueue                               !Format a queue element
  146.       #INSERT(%GetSecondaryRecords)
  147.   #FOR(%Formula)
  148.     #IF(UPPER(%FormulaClass) = 'LIST')
  149.       #INSERT(%Generateformula)
  150.     #ENDIF
  151.   #ENDFOR
  152.       #EMBED('LIST Class formula')
  153.   #FIX(%ScreenField,'?List')
  154.        Queue = %ScreenFieldExpression            !Format the queue line
  155.     OF ProcessField                              !Process a field
  156.   #FOR(%Formula)
  157.     #IF(UPPER(%FormulaClass) = 'LIST')
  158.     #ELSIF(UPPER(%FormulaClass) = 'FILTER')
  159.     #ELSIF(UPPER(%FormulaClass) = 'AVG')
  160.     #ELSIF(UPPER(%FormulaClass) = 'SUM')
  161.     #ELSIF(UPPER(%FormulaClass) = 'CNT')
  162.     #ELSE
  163.       #INSERT(%GenerateFormula)
  164.     #ENDIF
  165.   #ENDFOR
  166.       #EMBED('End of General Formulas')
  167.   #IF(%HotkeyExists)
  168.       CASE KEYCODE()
  169.     #FOR(%HotKey)
  170.       OF %HotKey                                 !User defined HotKey
  171.         %HotKeyProc                              !HotKey Procedure
  172.     #ENDFOR
  173.       END
  174.   #ENDIF
  175.       IF SELECTED() <> FIELD()                   ! If a new field is selected
  176.         CASE SELECTED()                          ! Jump to setup routine
  177.         #INSERT(%ScreenSetupRoutines)
  178.         END
  179.         #IF(%KeyRangeField)
  180.         IF SELECTED() = ?List
  181.           #IF(%TotalExists)
  182.             #IF(%PreListEntry)
  183.           SAV::RangeValueChanged = False
  184.           IF InitTotals
  185.             SAV::RangeValueChanged = True
  186.             InitTotals = False
  187.           ELSE
  188.             #INSERT(%RangeComparison)
  189.               SAV::RangeValueChanged = True
  190.             END
  191.           END
  192.             #ENDIF
  193.           #ENDIF
  194.           #INSERT(%SaveRangeFields)
  195.           #IF(%TotalExists)
  196.             #IF(%PreListEntry)
  197.           IF SAV::RangeValueChanged
  198.             DO InitializeTotals
  199.           END
  200.           #INSERT(%RestoreRangeFields)
  201.             #ENDIF
  202.           #ENDIF
  203.         END
  204.         #ENDIF
  205.       END                                        ! End IF
  206.       CASE FIELD()                               !Jump to edit routine
  207.   #FOR(%ScreenField)
  208.     #IF(%ScreenField = '?Insert')
  209.       #INSERT(%EditCodeInsert)
  210.     #ELSIF(%ScreenField = '?Change')
  211.       #INSERT(%EditCodeChange)
  212.     #ELSIF(%ScreenField = '?Delete')
  213.       #INSERT(%EditCodeDelete)
  214.     #ELSIF(%ScreenField = '?Select')
  215.       OF ?Select
  216.         #INSERT(%LookupValidateCode)
  217.     #ELSIF(%ScreenField = '?List')
  218.       #INSERT(%EditCodeList)
  219.     #ELSIF(%ScreenField = '?Cancel')
  220.       #INSERT(%EditCodeCancel)
  221.     #ELSIF(%ScreenField = '?Exit')
  222.       #INSERT(%EditCodeExit)
  223.     #ELSIF(%ScreenFieldUse=%Locator)
  224.       #INSERT(%EditCodeLocator)
  225.     #ELSE
  226.       #INSERT(%ScreenEditRoutines)
  227.     #ENDIF
  228.   #ENDFOR
  229.       #INSERT(%PulldownEditRoutines)
  230.       END                                        !End CASE FIELD()
  231.     OF NoRecords                                 !No records to browse
  232.       #EMBED('Case Of No Records Found')
  233.       #INSERT(%ClearFileFields)
  234.       #INSERT(%RestoreRangeFields)
  235.       DISPLAY
  236.       IF RECORDS(%Primary)                     #<!If file is not empty
  237.         IF ?List <> %FirstEntryField           #<!  And list is not first
  238.           SELECT(%FirstEntryField)             #<!    Select the first field
  239.         ELSE                                     !  From the first field
  240.   #IF(%UpdateProc)
  241.     #IF(%InsertExists)
  242.           SELECT(?Insert)                        !   Select the Insert Button
  243.     #ELSE
  244.           #INSERT(%RestoreRangeFields)
  245.           SETKEYCODE(InsKey)                     !   Ask for a new record
  246.           DO UpdateProcedure                     !   Call the update procedure
  247.           IF POSITION(%DisplayKey) = ''        #<!   If record not added
  248.             BREAK                                !    Return to caller
  249.           END                                    !   End IF
  250.     #ENDIF
  251.   #ELSE
  252.           BREAK                                  !   Return to caller
  253.   #ENDIF
  254.         END                                      !  End IF
  255.       ELSE                                       !If file is empty
  256.   #IF(%UpdateProc)
  257.         #INSERT(%ClearFileFields)
  258.         #INSERT(%RestoreRangeFields)
  259.         SETKEYCODE(InsKey)                       !  Ask for a new record
  260.         Do UpdateProcedure                       ! Call the update procedure
  261.         IF RECORDS(%Primary) = 0               #<!  If a record was not added
  262.           BREAK
  263.         END                                      !  End IF
  264.   #ELSE
  265.         BREAK                                    !  Return to caller
  266.   #ENDIF
  267.       END                                        !End IF
  268.   #IF(%FilterExists OR %KeyRangeField)
  269.     OF FilterRecord                              !Should we add this record
  270.       IF ButtonIsDisabled
  271.     #IF(%ChangeExists)
  272.         ENABLE(?Change)                          ! Enable the change button
  273.     #ENDIF
  274.     #IF(%DeleteExists)
  275.         ENABLE(?Delete)                          ! Enable the delete button
  276.     #ENDIF
  277.         ButtonIsDisabled = FALSE
  278.       END
  279.       #INSERT(%CheckKeyRangeFields)
  280.     #IF(%RecordFilter)
  281.       IF ~(%RecordFilter)                      #<!If Filter condition not met
  282.         GET(%Primary,0)                        #<! Dereference the record
  283.         CYCLE                                    ! Return to Top of LOOP
  284.       END                                        !End IF
  285.     #ELSE
  286.       #FOR(%Formula)
  287.         #IF(UPPER(%FormulaClass) = 'FILTER')
  288.           #IF(%FormulaType <> 'COMPUTED')
  289.       IF ~(%FormulaCondition)                  #<!If Filter condition not met
  290.         GET(%Primary,0)                        #<! Dereference the record
  291.         CYCLE                                    ! Return to Top of LOOP
  292.       END                                        !End IF
  293.           #ELSE
  294.       IF ~(%FormulaComputation)                #<!If Filter condition not met
  295.         GET(%Primary,0)                        #<! Dereference the record
  296.         CYCLE                                    ! Return to Top of LOOP
  297.       END                                        !End IF
  298.           #ENDIF
  299.         #ENDIF
  300.       #ENDFOR
  301.     #ENDIF
  302.       #EMBED('After Filter and Range Check')
  303.   #ENDIF
  304.  
  305.     OF ResetFirst                                !Set to first in a Range
  306.   #IF(%KeyRangeField)
  307.       #INSERT(%ClearRecordLow)
  308.       #INSERT(%RestoreRangeFields)
  309.       SET(%DisplayKey,%DisplayKey)             #<! SET to the closest match
  310.   #ELSE
  311.       IF InitialLoad
  312.         SET(%DisplayKey,%DisplayKey)           #<! SET to the closest match
  313.         InitialLoad = False
  314.       ELSE
  315.         SET(%DisplayKey)
  316.       END
  317.   #ENDIF
  318.       #EMBED('Set to First Record')
  319.  
  320.     OF ResetLast                                 !Set to last in a Range
  321.   #IF(%KeyRangeField)
  322.       #INSERT(%ClearRecordHigh)
  323.       #INSERT(%RestoreRangeFields)
  324.       SET(%DisplayKey,%DisplayKey)             #<! SET to the closest match
  325.   #ELSE
  326.       SET(%DisplayKey)                         #<! SET to the closest match
  327.   #ENDIF
  328.       #EMBED('Set to Last Record')
  329.  
  330.   #IF(%HotBar)
  331.     OF ProcessSelected                           !Process highlighted record
  332.       #INSERT(%GetSecondaryRecords)
  333.     #FOR(%Formula)
  334.       #IF(UPPER(%FormulaClass) = 'FILTER')
  335.       #ELSIF(UPPER(%FormulaClass) = 'AVG')
  336.       #ELSIF(UPPER(%FormulaClass) = 'SUM')
  337.       #ELSIF(UPPER(%FormulaClass) = 'CNT')
  338.       #ELSE
  339.       #INSERT(%GenerateFormula)
  340.       #ENDIF
  341.     #ENDFOR
  342.       #EMBED('Process Selected Record')
  343.       #SET(%ListFieldNumber,%Null)
  344.       #SET(%LastFieldNumber,%Null)
  345.       #FOR(%ScreenField)
  346.         #SET(%LastFieldNumber,(%LastFieldNumber+1))
  347.         #IF(UPPER(%ScreenField)='?LIST')
  348.           #SET(%ListFieldNumber,(%LastFieldNumber+1))
  349.         #ENDIF
  350.       #ENDFOR
  351.       DISPLAY(%ListFieldNumber,%LastFieldNumber) #<! Display the hot fields
  352.   #ENDIF
  353.     END                                          !End CASE
  354.   END                                            !End LOOP
  355.   DO ProcedureReturn
  356.  
  357. #IF(%TotalExists)
  358. !─────────────────────────────────────────────────────────────────────────────
  359. InitializeTotals ROUTINE
  360.   Total:Posit" = POSITION(%Primary)
  361.   #IF(%KeyRangeField)
  362.   CLEAR(%FilePre:RECORD,-1)
  363.   #INSERT(%RestoreRangeFields)
  364.   SET(%PrimaryKey,%PrimaryKey)                   #<! SET to the closest match
  365.   #ELSE
  366.   SET(%PrimaryKey)                               #<! SET to top of file
  367.   #ENDIF
  368.   #INSERT(%ClearTotalValues)
  369.   #EMBED('Set to First Record Before Total Loop')
  370.   LOOP
  371.     NEXT(%Primary)
  372.     IF ERRORCODE() THEN BREAK.
  373.     #EMBED('Inside Total Loop, Immediatly After NEXT()')
  374.   #IF(%KeyRangeField)
  375.     #INSERT(%RangeComparison)
  376.       BREAK
  377.     END
  378.   #ENDIF
  379.   #IF(%RecordFilter)
  380.     IF ~(%RecordFilter)                          #<!If Filter condition not met
  381.       CYCLE                                      #<! Return to Top of LOOP
  382.     END                                          #<!End IF
  383.   #ELSE
  384.     #FOR(%Formula)
  385.       #IF(UPPER(%FormulaClass) = 'FILTER')
  386.         #IF(%FormulaType <> 'COMPUTED')
  387.     IF ~(%FormulaCondition)                    #<!If Filter condition not met
  388.       CYCLE                                      ! Return to Top of LOOP
  389.     END                                          !End IF
  390.         #ELSE
  391.     IF ~(%FormulaComputation)                  #<!If Filter condition not met
  392.       CYCLE                                      ! Return to Top of LOOP
  393.     END                                          !End IF
  394.         #ENDIF
  395.       #ENDIF
  396.     #ENDFOR
  397.   #ENDIF
  398.   #FOR(%Formula)
  399.     #IF(UPPER(%FormulaClass) = 'FILTER')
  400.       #IF(%FormulaType <> 'COMPUTED')
  401.     IF ~(%FormulaCondition)                    #<!If Filter condition not met
  402.       CYCLE                                      ! Return to Top of LOOP
  403.     END                                          !End IF
  404.       #ELSE
  405.     IF ~(%FormulaComputation)                  #<!If Filter condition not met
  406.       CYCLE                                      ! Return to Top of LOOP
  407.     END                                          !End IF
  408.       #ENDIF
  409.     #ENDIF
  410.   #ENDFOR
  411.     #INSERT(%GetSecondaryRecords)
  412.     #EMBED('Inside Total Loop, After Filter')
  413.     #INSERT(%AddTotalValues)
  414.   END
  415.   #INSERT(%UpdateTotalValues)
  416.   #EMBED('After Total Field Loop')
  417.   #IF(%KeyRangeField)
  418.   CLEAR(%FilePre:RECORD,-1)
  419.   #INSERT(%RestoreRangeFields)
  420.   #ENDIF
  421.   IF Total:Posit"
  422.     RESET(%Primary,Total:Posit")
  423.     NEXT(%Primary)
  424.   END
  425.   DISPLAY
  426. #ENDIF
  427.  
  428. #IF(%UpdateProc)
  429. !─────────────────────────────────────────────────────────────────────────────
  430. UpdateProcedure ROUTINE
  431.   #INSERT(%TotalBeforeUpdate)
  432.   #EMBED('Prior to Update Procedure')
  433.   %UpdateProc
  434.   #INSERT(%IsUpdateSuccessful)
  435.   #EMBED('After Update Procedure')
  436.   #INSERT(%TotalAfterUpdate)
  437.   #INSERT(%RestoreRangeFields)
  438.   #IF(%KeyRangeField)
  439.   CLEAR(%FilePre:RECORD,-1)
  440.   #INSERT(%RestoreRangeFields)
  441.   #ENDIF
  442.   SELECT(?List)
  443. #ENDIF
  444. #!
  445. !─────────────────────────────────────────────────────────────────────────────
  446. ProcedureReturn ROUTINE
  447.   IF ListInitialized
  448.     EndBrowse                                    !End the browse session
  449.   END
  450.   FREE(Queue)                                    !Free the Queue memory
  451.   #IF(%Pulldown)                                #!If a Pulldown exists
  452.   IF SAV::PullDownOpened
  453.     CLOSE(%Pulldown)                           #<!Close the Pulldown
  454.     SAV::PullDownOpened = False
  455.   END
  456.   #ENDIF
  457.   #EMBED('Before Closing Files')
  458.   #INSERT(%FileControl)
  459.   DO EndOfProcedureEmbed
  460.   RETURN
  461. !─────────────────────────────────────────────────────────────────────────────
  462. EndOfProcedureEmbed ROUTINE
  463. #EMBED('End of Procedure')
  464. #EMBED('Custom Routines')
  465. #CHAIN('Select.tpx')
  466.